package Utils;
import java.util.ArrayList;
import java.util.Collection;


public class Ticket {
	public enum field {
		numero(0),
		type(1),
		composant(2),
		version(3),
		severity(4),
		status(5),
		description(5);
		
		private int _indexInString;
		
		private field(int index)
		{
			_indexInString = index;
		}
		
	}
	public ArrayList<String> fields;
	
	public Ticket(String line){
		fields = new ArrayList<String>();
		String[] tokens = line.split(" ");
		int i;
		for(i = 0; i < field.values().length; i++)
			fields.add(tokens[i]);
		String lastItem = fields.get( field.description.ordinal() );
		while(i < tokens.length){
			lastItem += " "+tokens[i];
			i++;
		}
		fields.set( field.description.ordinal(), lastItem );
	}
	
	public String toString(){
		ArrayList<String> fieldsCopy = (ArrayList<String>)fields.clone();
		String str = fieldsCopy.remove(0);
		for(Object o : fieldsCopy)
			str += " "+o;
		return str;
	}
	
	public Collection<String> getFields()
	{
		return (Collection<String>)fields.clone();
	}
	public String getField(field fieldToGet)
	{
		return fields.get(fieldToGet._indexInString);
	}
	
	public String removeField(int i){
		return fields.remove(i);
	}	
	
	public void setFields(Collection<String> collection){
		ArrayList<String> arraylist = new ArrayList<String>();
		arraylist.addAll(collection);
		fields = arraylist;
	}
	
	//For testing...
	public static void main(String[] args) {
		Ticket t = new Ticket("0001 AME LAB001 01.01 MAJ NOU Modifier le lab 1 de LOG430");
		for(Object o : t.getFields())
			System.out.println(o);
		System.out.println("----------");
		System.out.println(t);
	}
}
